package com.example.javamediaserver.model;

import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.nio.file.Path;
import java.time.LocalDateTime;

@Entity
@Table(name = "recordings")
@Data
public class Recording {

    @Id
    private String id;
    
    private String fileName;
    private String filePath;
    private String streamPath;
    private String app;
    private String streamKey;
    
    private LocalDateTime createdTime;
    private long fileSize;
    private long durationInSeconds;
    
    // 计算URL（用于前端访问）
    public String getUrl() {
        return "/recordings/" + fileName;
    }
    
    // 从文件名解析元数据
    public void parseFromFileName() {
        if (fileName != null && fileName.endsWith(".flv")) {
            String baseName = fileName.substring(0, fileName.length() - 4);
            String[] parts = baseName.split("_");
            
            if (parts.length > 0) {
                this.app = parts[0];
            }
            
            if (parts.length > 1) {
                this.streamKey = parts[1];
            }
            
            // 如果文件名包含日期时间信息，可以进一步解析
        }
    }
} 